package com.lindroid.androiduilearning.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.lindroid.androiduilearning.R;
import com.lindroid.androiduilearning.base.BaseActivity;
import com.lindroid.androiduilearning.checkedtextview.CheckedTextViewActivity;
import com.lindroid.androiduilearning.expandablelistview.ExpandableListViewActivity;
import com.lindroid.androiduilearning.flexboxlayout.FlexboxLayoutActivity;
import com.lindroid.androiduilearning.recyclerview.RecyclerViewActivity;
import com.lindroid.androiduilearning.textview.TextViewActivity;
import com.lindroid.androiduilearning.util.ActivityUtil;

/**
 * @author lin
 */
public class CatalogActivity extends BaseActivity {

    private ListView listCatalog;
    private Activity context;
    private String[] uiNames;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_catalog);
        context = this;
        uiNames = getResources().getStringArray(R.array.UIList);
        initView();
        initBlueToolBar("目录", false);
    }

    private void initView() {
        listCatalog = findViewById(R.id.list_catalog);
        ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(this, R.array.UIList, android.R.layout.simple_list_item_1);
        listCatalog.setAdapter(arrayAdapter);
        listCatalog.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        ActivityUtil.startActivity(context, ExpandableListViewActivity.class);
                        break;
                    case 1:
                        ActivityUtil.startActivity(context, TextViewActivity.class);
                        break;
                    case 2:
                        ActivityUtil.startActivity(context, FlexboxLayoutActivity.class);
                        break;
                    case 3:
                        ActivityUtil.startActivity(context, CheckedTextViewActivity.class);
                        break;
                    case 4:
                        ActivityUtil.startActivity(context, RecyclerViewActivity.class);
                        break;
                    default:
                        break;
                }
            }
        });
    }
}
